package ch.mylonas.saometer.visualization;

import processing.core.PApplet;
import ch.mylonas.saometer.config.SaoMeterConfig;
import ch.mylonas.saometer.data.processing.Punch;

public class PunchGraph {
	SaoMeterConfig saoMeterConfig;
	
	PApplet parent;
	int x;
	int y;
	int width;
	int height;
	int step_size;
	int color;
	
	public PunchGraph() {
		super();
		
	}
	
	public void init(){
		
	}
	
	public void draw(Punch punch){
		this.step_size = (int) this.width/(punch.getData().length);
		
		parent.strokeWeight(2);
		parent.stroke(this.color);
		int lastY = (int) ((float) this.height/saoMeterConfig.getMaxDataValue()*punch.getData()[0]);
		
		
        for(int i=1; i<punch.getData().length; i++){
        		
                int newY = (int) ((float)this.height / saoMeterConfig.getMaxDataValue() * punch.getData()[i]);
                int x1 = i*this.step_size + this.x;
                int x2 = (i+1)*this.step_size + this.x;
                
                // draw the line
                parent.line(x1, lastY + this.y, x2, newY + this.y);
                
                lastY = newY;
        }
        
		parent.strokeWeight(1);
        
	}
	
	public void setColor(int color){
		this.color = color;
	}
	
	public void setParent(PApplet parent){
		this.parent = parent;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public void setSaoMeterConfig(SaoMeterConfig saoMeterConfig) {
		this.saoMeterConfig = saoMeterConfig;
	}
}
